<?php
namespace Model; 
use Think\Model;

class QuestionModel extends Model {
	/**
	 * 写文件
	 * @return boolean
	 */
	function writefile($dirname,$content) {
		$filename = substr(str_shuffle('qwertyuiopasdfghjklzxcvbnm1234567890'),0,9);
		$filepath = $dirname . date('Ymd');
		$path = $filepath . '/' . $filename . '.html';
		if ($this->mk_dir($filepath)) {
			if ($handle = fopen($path, w)) {
				fwrite($handle, $content);
				fclose($handle);
				return $path;
			} 
		} else {
			return false;
		}
	}
	/**
	 * 创建目录
	 * @param 目录 $path
	 * @return boolean
	 */
	function mk_dir($path) {
		if (is_dir($path)) {
			return true;
		}
	
		return is_dir(dirname($path))||self::mk_dir(dirname($path))?mkdir($path):false;
	}
	/**
	 * 读文件
	 */
	function readfile($filename) {
		$file = fopen($filename, 'r');
		$z = fread($file, filesize($filename));
		return $z;
		fclose($filename);
	}
	
	function batch($check) {
		$info = $this->where('id ' . 'IN(' . $check . ')')->select();
		unlink($info['content']);unlink($info['answer']);
		$z = $this->where('id ' . 'IN(' . $check . ')')->delete();
		return $z;
	}
}